import Vue from 'vue';
import Vuex from 'vuex';
import * as actions from './actions';
import operaionManageFilter from './modules/operaionManageFilter';
import workSheet from './modules/workSheet';
import energyConsume from './modules/energyConsume';
import safetyCheck from './modules/safetyCheck';
import { stat } from 'fs';

Vue.use(Vuex);

const store = new Vuex.Store({
  actions,
  modules: {
    operaionManageFilter,
    workSheet,
    energyConsume,
    safetyCheck,
  },
  state: {
    radioObj: null, //点击对象
    //底部栏index
    mode: 0,
    //设备信息
    deviceMessage: null,
    //记录详情
    detail: null,
    //设备部件列表
    deviceComponent: null,
    //用户信息
    user: null,
    //位置
    position: null,
    //部件信息
    deviceInfo: null,
    //部件信息
    componentData: null,
    pageNum: null,
    departmentData: null,
    workSheetInfo: {},
    produceDataStatus: false,
    produceDataCheck: false,
    filterCache: {},
    appMenuList: [],
    application: {
      pageName: '',
      pageId: '',
      moduleId: '',
      cloudPageId: '',
    },
    applicationList: [],
  },
  mutations: {
    setRadio(state, n) {
      state.radioObj = n;
    },
    setFilterCache(state, n) {
      state.filterCache = n;
    },
    changeMode(state, n) {
      // 变更状态
      state.mode = n;
    },
    changeDeviceMessage(state, detail) {
      // 保存查看设备信息
      state.deviceMessage = detail;
      localStorage.setItem('deviceMessage', JSON.stringify(detail));
    },
    saveDetail(state, detail) {
      // 保存查看设备信息
      state.detail = detail;
      localStorage.setItem('detail', JSON.stringify(detail));
    },
    saveDeviceComponent(state, detail) {
      // 保存查看设备信息
      state.deviceComponent = detail;
      localStorage.setItem('deviceComponent', JSON.stringify(detail));
    },
    saveUser(state, detail) {
      // 保存查看设备信息
      state.user = detail;
      localStorage.setItem('user', JSON.stringify(detail));
    },
    savePosition(state, position) {
      state.position = position;
    },
    saveWorkSheetInfo(state, detail) {
      state.workSheetInfo = detail;
    },
    saveComponentData(state, detail) {
      // 保存查看设备信息
      state.componentData = detail;
      localStorage.setItem('componentData', JSON.stringify(detail));
    },
    saveDeviceInfoData(state, detail) {
      // 保存查看设备信息
      state.deviceInfo = detail;
    },
    changeDepartmentData(state, data) {
      state.departmentData = data;
    },
    changePageNum(state, pageNum) {
      state.pageNum = pageNum;
    },
    checkId(state, curId) {
      //保存巡检选厂的id
      state.curId = curId;
      localStorage.setItem('curId', JSON.stringify(curId));
    },
    changeProduceDataStatus(state, n) {
      // 变更状态
      state.produceDataStatus = !state.produceDataStatus;
    },
    changeProduceDataCheck(state, n) {
      // 变更状态
      state.produceDataCheck = !state.produceDataCheck;
    },
    setAppMenu(state, data) {
      state.appMenuList = data;
    },
    setApplication(state, data) {
      state.application = data;
    },
    setApplicationList(state, data) {
      state.applicationList = data;
    },
  },
  getters: {
    getProduceDataStatus: (state) => {
      return state.produceDataStatus;
    },
  },
});

export default store;
